package com.kamenrider.adventureaffiliated.mixin;

import com.kamenrider.adventureaffiliated.item.AnotherBuildArmorItem;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
 * Mixin class for inventory menu slot functionality.
 *
 * @author QianYunYi
 */
@Mixin(targets = "net/minecraft/world/inventory/InventoryMenu$1")
public abstract class InventoryMenuSlotMixin {

    @Inject(
            method = "mayPickup(Lnet/minecraft/world/entity/player/Player;)Z",
            at = @At("HEAD"),
            cancellable = true
    )
    private void preventArmorPickup(Player player, CallbackInfoReturnable<Boolean> callback) {
        Slot slot = (Slot)(Object)this;
        ItemStack stack = slot.getItem();
//        System.out.println("玩家 Henshen 状态: " + player.getPersistentData().getAllKeys());
//        System.out.println("Henshen_active 类型: " + player.getPersistentData().getTagType("henshen_active"));
//        System.out.println("Henshen_active 值: " + player.getPersistentData().get("henshen_active"));
//        System.out.println("当前槽位物品: " + stack.getItem().getRegistryName());
//        System.out.println("原本的 mayPickup 返回值: " + callback.getReturnValue());
        // 阻止拾取盔甲
        if (player.getPersistentData().getBoolean("adventure_affiliated:henshen_active")||stack.getItem() instanceof AnotherBuildArmorItem) {
            callback.setReturnValue(false);
        }
    }
}